#include <stdio.h>
#include<stdlib.h>
#define InitSize 10
typedef struct{
	int *data;
	int length;
	int MaxSize;
}SqList;
void InitList(SqList *list){//初始化。为传过来的结构体开辟内存空间
//	printf("%d",list->length);
	list->data = (int *)malloc(sizeof(int) * InitSize);
	if(list->data==NULL)//判断空间是否开辟成功
	{
		printf("malloc fail\n");
		exit(0);
	}
	list->length = 0;
	list->MaxSize = InitSize;
}
void ListInsert(){
	
}
void listOutput(SqList *list){
	printf("顺序表的长度为:%d\n",list->length);
	for(int i=0;i<list->length;i++){
		printf("%d\n",list->data[i]);
	}
}
void ListInput(SqList *list){
	printf("请输入你要输入的数字,-1以结束输入!\n");
	int data,i;
	i = 0;
	while(scanf("%d",&data) && data!=-1){
		list->data[list->length++] = data;
	}
	
}
void ListDelete(SqList *list,int index,int *e){
	if(index<0||index>list->length-1){
		printf("出错了！");
		return;
	}
	*e = list->data[index];//将要删除的值保存到e指向的空间里面
	for(int i= index;i<list->length;i++){
		list->data[i] = list->data[i+1];
	}
	list->length--;
	return;
}
void DeleMinValue(SqList *list,int *e){
	int min = list->data[0];int index = 0;//假设第一个是最小的
	for(int i=0;i<list->length;i++){
		if(min > list->data[i]){
			min = list->data[i];
			index = i;
		}
	}
	ListDelete(list, index, e);
}
int main() {
	SqList *list = (SqList*) malloc(sizeof(SqList));
	InitList(list);
	ListInput(list);
	listOutput(list);
	int e;
	DeleMinValue(list, &e);
	printf("删除的元素为：%d\n",e);
	printf("删除最小值的新顺序表为:\n");
	listOutput(list);
}